﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	class GenParse_MeasurementType
	{
		#region private constants

		private const byte Temperature_Byte = 0x01;
		private const byte TemperatureGradient_Byte = 0x03;
		private const byte LightIntensity_Byte = 0x04;
		private const byte WindSpeed_Byte = 0x05;
		private const byte Pressure_Byte = 0x06;
		private const byte Humidity_Byte = 0x07;
		private const byte FlowRate_Byte = 0x08;
		private const byte GasQuota_Byte = 0x09;
		private const byte Tension1_Byte = 0x20;
		private const byte Tension2_Byte = 0x21;
		private const byte Current1_Byte = 0x30;
		private const byte Current2_Byte = 0x31;
		private const byte Energy_Byte = 0x40;
		private const byte Power_Byte = 0x48;
		private const byte RadioactiveEnergyDose_Byte = 0x50;

		#endregion private constants

		#region internal methods

		internal static byte GenerateByte(eMeasurementType measurementType)
		{
			byte measurementTypeByte = 0x0;

			switch (measurementType)
			{
				case eMeasurementType.Current1_mAmpere:
					measurementTypeByte = Current1_Byte;
					break;
				case eMeasurementType.Current2_Ampere:
					measurementTypeByte = Current2_Byte;
					break;
				case eMeasurementType.Energy:
					measurementTypeByte = Energy_Byte;
					break;
				case eMeasurementType.FlowRate:
					measurementTypeByte = FlowRate_Byte;
					break;
				case eMeasurementType.GasQuota:
					measurementTypeByte = GasQuota_Byte;
					break;
				case eMeasurementType.Humidity:
					measurementTypeByte = Humidity_Byte;
					break;
				case eMeasurementType.LightIntensity:
					measurementTypeByte = LightIntensity_Byte;
					break;
				case eMeasurementType.Power:
					measurementTypeByte = Power_Byte;
					break;
				case eMeasurementType.Pressure:
					measurementTypeByte = Pressure_Byte;
					break;
				case eMeasurementType.RadioactiveEnergyDose:
					measurementTypeByte = RadioactiveEnergyDose_Byte;
					break;
				case eMeasurementType.Temperature:
					measurementTypeByte = Temperature_Byte;
					break;
				case eMeasurementType.TemperatureGradient:
					measurementTypeByte = TemperatureGradient_Byte;
					break;
				case eMeasurementType.Tension1_mVolt:
					measurementTypeByte = Tension1_Byte;
					break;
				case eMeasurementType.Tension2_Volt:
					measurementTypeByte = Tension2_Byte;
					break;
				case eMeasurementType.WindSpeed:
					measurementTypeByte = WindSpeed_Byte;
					break;
				default:
					// TODO handle error (unknown value for measurementType)
					break;
			}

			return measurementTypeByte;
		}

		internal static bool ParseByte(byte measurementTypeByte, out eMeasurementType measurementType)
		{
			// set default value
			bool bRetVal = true;
			measurementType = eMeasurementType.WindSpeed;

			switch (measurementTypeByte)
			{
				case Temperature_Byte:
					measurementType = eMeasurementType.Temperature;
					break;
				case TemperatureGradient_Byte:
					measurementType = eMeasurementType.TemperatureGradient;
					break;
				case LightIntensity_Byte:
					measurementType = eMeasurementType.LightIntensity;
					break;
				case WindSpeed_Byte:
					measurementType = eMeasurementType.WindSpeed;
					break;
				case Pressure_Byte:
					measurementType = eMeasurementType.Pressure;
					break;
				case Humidity_Byte:
					measurementType = eMeasurementType.Humidity;
					break;
				case FlowRate_Byte:
					measurementType = eMeasurementType.FlowRate;
					break;
				case GasQuota_Byte:
					measurementType = eMeasurementType.GasQuota;
					break;
				case Tension1_Byte:
					measurementType = eMeasurementType.Tension1_mVolt;
					break;
				case Tension2_Byte:
					measurementType = eMeasurementType.Tension2_Volt;
					break;
				case Current1_Byte:
					measurementType = eMeasurementType.Current1_mAmpere;
					break;
				case Current2_Byte:
					measurementType = eMeasurementType.Current2_Ampere;
					break;
				case Energy_Byte:
					measurementType = eMeasurementType.Energy;
					break;
				case Power_Byte:
					measurementType = eMeasurementType.Power;
					break;
				case RadioactiveEnergyDose_Byte:
					measurementType = eMeasurementType.RadioactiveEnergyDose;
					break;
				default:
					// TODO handle error (unknown value for measurementTypeByte)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}	

		#endregion internal methods
	}
}
